<script>
import axios from "axios";

export default {
  name: "addDialog",
  data() {
    return {
      dialogTableVisible: false,
      dialogFormVisible: false,
      form: {
        name: "",
        intro: "",
        createTime: "",
        updateTime: "",
        managerId: "",
        parentId: "",
        path: "",
        state: ""
      },
      options: [],
      formLabelWidth: '120px',
      value: "",
      a:""
    }
  },
  methods: {
    sendDataParent: function () {
      console.log("执行取消")
      console.log(this.$emit)
      this.$emit('closeDialog', false);
    },
    insertData() {
      this.form.managerId =
      axios.post("http://localhost:8088/departments", this.form).then(
          function (res) {
            console.log("请求成功")
            console.log(res.data)

          },
          function (error) {
            console.log("请求失败")
          }
      )
      this.$emit('closeDialog', false);
      this.$emit('refresh', true);
    },
    showManager(value) {
      this.form.managerId = value.charAt(value.length - 1)
    }
  },
  props: ['dialogFormShow'],
  mounted() {
  },
  watch: {
    dialogFormShow: function (newValue, oldValue) {
      if (newValue === true) {
        let vue = this
        axios.get("http://localhost:8088/employeeAndRoles/RoleId/" + "1").then(
            function (res) {
              console.log("请求成功")
              console.log(res.data)
              vue.emps = res.data.data
              vue.options = res.data.data
              console.log(vue.options)
            },
            function (error) {
              console.log("请求失败")
            }
        )
      }
    }
  }
}
</script>

<template>
  <el-container>
    <el-dialog title="新增部门" :visible.sync="dialogFormShow" @close="sendDataParent">
      <el-form :model="form">
        <el-input type="hidden" v-model="form.id"></el-input>
        <el-form-item label="部门名称" :label-width="formLabelWidth">
          <el-input v-model="form.departmentName" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="部门介绍" :label-width="formLabelWidth">
          <el-input v-model="form.intro" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="创建时间" :label-width="formLabelWidth">
          <el-input v-model="form.createTime" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="修改时间" :label-width="formLabelWidth">
          <el-input v-model="form.updateTime" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="部门经理" :label-width="formLabelWidth">
          <el-select v-model="value" placeholder="请选择" @change="showManager">
            <el-option
                v-for="item in options"
                :key="item.employee.id"
                :value="item.employee.username+'-'+item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="上级部门" :label-width="formLabelWidth">
          <el-input v-model="form.parentId" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="path" :label-width="formLabelWidth">
          <el-input v-model="form.path" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="state" :label-width="formLabelWidth">
          <el-input v-model="form.state" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="sendDataParent">取 消</el-button>
        <el-button type="primary" @click="insertData">确 定</el-button>
      </div>
    </el-dialog>
  </el-container>
</template>

<style scoped>

</style>
